<template>
  <div class="xtx-checkbox" @click="changeChecked">
      <i class="iconfont icon-checked" v-if="checked" ></i>
      <i class="iconfont icon-unchecked" v-else></i>
      <span v-if="$slots.default"><slot /></span>
  </div>
</template>

<script>
// import { ref, watch } from 'vue'
import { useVModel } from '@vueuse/core'
export default {
  name: 'XtxCheckbox',
  props: {
    modelValue: {
      type: Boolean,
      default: false
    }
  },
  setup (props, { emit }) {
    const checked = useVModel(props, 'modelValue', emit)
    // console.log(checked.value)

    const changeChecked = () => {
      // 通知父组件
      // const newVal = !checked.value
      checked._value = !checked._value

      //   让组件支持change事件
      emit('change', checked._value)
    }
    return { checked, changeChecked }
  }
}
</script>

<style scoped lang='less'>
  // 筛选区
 .xtx-checkbox {
  display: inline-block;
  margin-right: 2px;
  .icon-checked {
    color: @xtxColor;
    ~ span {
      color: @xtxColor;
    }
  }
  i {
    position: relative;
    top: 1px;
  }
  span {
    margin-left: 2px;
  }
}
  </style>
